/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.uac.pages.home;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import com.eelpo.cmmp.core.exception.ServiceException;
import com.eelpo.cmmp.core.wicket.component.tree.LinkMenuTree;
import com.eelpo.cmmp.core.wicket.page.basic.DeniedPage;
import com.eelpo.cmmp.uac.services.IEntityManageService;
import com.eelpo.cmmp.uac.session.UACSession;

import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 * <pre>
 * 左边树菜单框架
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class LeftFrame extends DeniedPage {

	@SpringBean
	private IEntityManageService entityManageService;

	public LeftFrame() {

		renderLeftMenuTree();
	}

	public void renderLeftMenuTree() {

		DefaultTreeModel treeModel = null;

		try {
			treeModel = entityManageService.getMenuEntities(UACSession.get().getUserId());
		} catch (ServiceException e) {
			treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
		}

		LinkMenuTree tree = new LinkMenuTree("tree", treeModel);
		tree.setRootLess(true);
		tree.getTreeState().setAllowSelectMultiple(false);
		tree.getTreeState().expandAll();

		add(tree);
	}
}
